In [ ]:
Name = "John Doe" # String.
Age = 40 # Integer.
Height = 180.3 # Float.
Married = True # Boolean (True/False).
Children = ["Emma", "Thomas"] # List.
Female = False # Boolean (True/False).
Interests = [] # Empty list.
In [ ]:
celsius = 5
In [ ]:
# Write here
In [ ]:
population = 10000000
employed = 4568600
In [ ]:
# Round to 1 decimal.
round(3.3333333333, 1)
In [ ]:
Name = "John Doe"
text = "The quick brown fox jumps over the lazy dog"
In [ ]:
# Show the first, and fifth character.
print(text[0]) # Note, it starts with 0!
print(text[4])
In [ ]:
# Show the first 3 characters.
print(text[0:3])
In [ ]:
# Replace text.
print(text.replace("fox", "journalist"))
In [ ]:
# Make text lower case, UPPER CASE or Title Case.
print(text.lower())
print(text.upper())
print(text.title())
In [ ]:
# Character length.
len(text)
In [ ]:
# Find the word "quick". Returns position of first character.
print(text.find("quick"))
In [ ]:
# What happens when we don't find the word? It returns -1.
print(text.find("journalism"))
In [ ]:
Name = "John Doe" # String.
Age = 40 # Integer.
Height = 180.3 # Float.
Married = True # Boolean (True/False).
Children = ["Emma", "Thomas"] # List.
Female = False # Boolean (True/False).
Interests = [] # Empty list.
In [ ]:
if Age == 40:
print(Name + " is 40 years old.")
else:
print(Name + " is not 40 years old.")
In [ ]:
# Print a range of numbers.
for i in range(5):
print(i)
In [ ]:
# Print each name in the list.
for name in Children:
print(name)
Exercise: Write a function that check how many names starts with the letter E.
Break the task down in steps:
e_letters
with the value 0
. It will store the number of names with E.name.startswith("E")
function.e_letters
with 1.
In [ ]:
# A function that multiples two numbers together.
def calc(x, y):
return(x * y)
In [ ]:
calc(10, 5)
In [ ]:
-
In [ ]:
# Number of names in the list.
len(names)
In [ ]:
def countE(names):
# Write here...